<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_pay extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function get_item($lim=0, $num=0,$arr_where='')
	{
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('ttransactions');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		$this->db->order_by("trxid", "asc");
		if ($lim!=0){
			$this->db->limit($lim,$num);
		}
		return $this->db->get();
	}
	
	function get_countitem($arr_where=''){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('tusers');
		if ($arr_where!=''){
			$this->db->where($arr_where);
		}
		return  $this->db->count_all_results();
	}
	
	function getItemById($id)
	{
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		return $this->db->get('users');
		
	}
/*
	function insert($data)
	{
		$this->db->flush_cache();
		$this->db->set('username', $data['username']); 
		$this->db->set('password', $data['password']); 
		$this->db->set('level_id', $data['level_id']); 

		
        $result = $this->db->insert('users');
		
		//$result=$this->db->insert('users', $data);
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} */
	
	function updatereferenceid($referenceid, $data)
	{
		$this->db->flush_cache();
		$this->db->set('closetrxdate', $data['closetrxdate']); 
$this->db->set('username', $data['username']); 
$this->db->set('appsid', $data['appsid']); 
$this->db->set('trxstatus', $data['trxstatus']); 
$this->db->set('mappsid', $data['mappsid']); 
$this->db->set('paymethodid', $data['paymethodid']); 
$this->db->set('paystatus', $data['paystatus']); 

		$this->db->where('referenceid', $referenceid);
		//$result=$this->db->update('tusers', $data);
		$result=$this->db->update('ttransactions');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
	
	function updatepay($referenceid, $data)
	{
		$this->db->flush_cache();
		$this->db->set('paymethod', $data['paymethod']); 
$this->db->set('paystatus', $data['paystatus']); 
 

		$this->db->where('referenceid', $referenceid);

		$result=$this->db->update('ttransactions');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
	function insertinbox($message)
	{
		$this->db->flush_cache();
		$this->db->set('userinbox', $message['userinbox']); 
		$this->db->set('usercat', $message['usercat']); 
		$this->db->set('channelid', $message['channelid']); 
		$this->db->set('serviceid', $message['serviceid']); 
		$this->db->set('referenceid', $message['referenceid']); 
		$this->db->set('mappsid', $message['mappsid']); 
		$this->db->set('operator', $message['operator']); 
		$this->db->set('amount', $message['amount']); 
		$this->db->set('closetrxdate', $message['closetrxdate']); 
		$this->db->set('username', $message['username']); 
		$this->db->set('appsid', $message['appsid']); 

		
        $result = $this->db->insert('tinbox');
		
		//$result=$this->db->insert('users', $data);
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
	function updateip($username, $data)
	{
		$this->db->flush_cache();
		$this->db->set('ip', $data['ip']); 
		$this->db->set('device', $data['device']); 
		$this->db->set('os', $data['os']); 
		$this->db->set('location', $data['location']); 

		$this->db->where('username', $username);
		//$result=$this->db->update('tusers', $data);
		$result=$this->db->update('tusers');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
	} 
/*	
	function delete($id)
	{
		
		$this->db->flush_cache();
		$this->db->where('userid', $id);
		$result = $this->db->delete('users');
		
		if($result) {
			return TRUE;
		}else {
			return FALSE;
		}
		
	}
	*/
}
